<?php

use App\Admin\Middleware\AuthenticateMiddleware;
use App\Admin\Middleware\PermissionsMiddleware;
use App\Route;
use App\Admin\Controller\Base;

// 登录
Route::get('login', [Base\LoginController::class, 'loginView']);
Route::post('login', [Base\LoginController::class, 'loginIn']);
Route::get('login-out', [Base\LoginController::class, 'loginOut']);

// 需要登录认证的
Route::group(function () {
    Route::get('/', [Base\IndexController::class, 'index']);
    Route::get('index', [Base\IndexController::class, 'index']);
    Route::get('home', [Base\IndexController::class, 'home']);
    Route::get('get-menu', [Base\IndexController::class, 'getMenu']);
    Route::post('upload', [Base\CommonController::class, 'upload']);
    Route::post('froala-upload', [Base\CommonController::class, 'froalaUpload']);

    // 需要权限验证的
    Route::group('base', function () {

        Route::resourceSc('administrators', Base\AdministratorsController::class);
        Route::post('administrators/switch-toggle', [Base\AdministratorsController::class, 'switchToggle']);
        Route::post('administrators/reseat-password', [Base\AdministratorsController::class, 'reseatPassword']);
        Route::post('administrators/login-account', [Base\AdministratorsController::class, 'loginAccount']);

        Route::resourceSc('role', Base\RoleController::class);
        Route::get('role/set-permission', [Base\RoleController::class, 'setPermission']);
        Route::post('role/set-permission', [Base\RoleController::class, 'savePermission']);

        Route::resourceSc('route', Base\RouteController::class);
        Route::resourceSc('super-config', Base\SuperConfigController::class);
        Route::get('super-config/base-config', [Base\SuperConfigController::class, 'baseConfig']);
        Route::post('super-config/update-base-config', [Base\SuperConfigController::class, 'updateBaseConfig']);
        Route::get('super-config/advanced-array-data', [Base\SuperConfigController::class, 'advancedArrayData']);
        Route::post('super-config/advanced-array-data-destroy', [Base\SuperConfigController::class, 'advancedArrayDataDestroy']);

        Route::post('update-password', [Base\UpdatePasswordController::class, 'updatePassword']);
        Route::rule('backup', [Base\DataBackUpController::class, 'backup'], 'GET|POST');
    })->middleware([PermissionsMiddleware::class]);
})->middleware([AuthenticateMiddleware::class]);